//
//  ONSOrderFooterView.m
//  OneNineteen
//
//  Created by apple on 2019/2/26.
//  Copyright © 2019 stoneobs.qq.com. All rights reserved.
//

#import "OEOrderFooterView.h"

@implementation OEOrderFooterView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    if (self == [super initWithReuseIdentifier:reuseIdentifier]) {
        [self configSubView];
    }
    return self;
}
+ (CGFloat)cellHeight{
    return 70;
}
#pragma mark --configSubView
- (void)configSubView{
    UIView * whiteView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 60)];
    whiteView.backgroundColor = UIColor.whiteColor;
    [self addSubview:whiteView];
}
- (STButton *)defultButtonWithName:(NSString*)name tag:(NSInteger)tag{
    __weak typeof(self) weakSelf =  self;
    STButton * buyButton = [[STButton alloc] initWithFrame:CGRectMake(0, 0, 80, 36)
                                                     title:name
                                                titleColor:OE_LIMITE_COLOR
                                                 titleFont:14
                                              cornerRadius:18
                                           backgroundColor:UIColor.whiteColor
                                           backgroundImage:nil
                                                     image:nil];
    buyButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
    CGFloat  witdh = [name st_widthWithheight:36 font:14];
    buyButton.width = witdh +36;
    buyButton.right = UIScreenWidth - 15;
    buyButton.tag = tag;
    buyButton.bottom = self.class.cellHeight - 15;
    [buyButton st_setBorderWith:0.5 borderColor:OE_LIMITE_COLOR cornerRadius:18];
    //    [buyButton st_setBorderWith:0.5 borderColor:TM_lineColor cornerRadius:16];
    [buyButton setClicAction:^(UIButton *sender) {
        if (weakSelf.onSelctedHandle) {
            weakSelf.onSelctedHandle(name);
        }
    }];
    return buyButton;
}
- (void)setModel:(OEOrderModel *)model{
    _model = model;
    
    for (STButton * button in self.subviews) {
        if ([button isKindOfClass:STButton.class] && button.tag > 10000) {
            [button removeFromSuperview];
        }
    }
    CGFloat right = UIScreenWidth - 15;
    NSMutableArray * array = model.cus_menuArray.mutableCopy;
    if (!model.cus_isDetailVC) {
        [array addObject:@"DETAIL"];
    }
    
    for (NSInteger i = 0; i < array.count; i ++) {
        NSString * name = array[i];
        STButton * button = [self defultButtonWithName:name tag:10001 + i];
        [self addSubview:button];
        button.right = right;
        right = button.left - 10;
    }
}
@end
